/***********************************************************************
 * Module:  Topic.java
 * Author:  DAC
 * Purpose: Defines the Class Topic
 ***********************************************************************/
package com.group1.model;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid c1132ded-0e4c-4d27-bce4-e05acf63aaa6 */
public class Topic {
   /** @pdOid de61ddd1-cd0c-46bc-bcf9-621734a7a747 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 2f0507f6-f913-4987-8cff-3e687e624d6e */
   public Integer topicId;
   /** @pdOid 359f1947-66d6-43b6-8cea-37b334fa968b */
   public java.lang.String topicName;
   /** @pdOid f9139b6c-4543-4fa4-8649-65a225a3f6e8 */
   public java.lang.String topicNote;
   
   /** @pdRoleInfo migr=no name=Question assc=questionOfTopic coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   private Set TopicQuestionMapping = new HashSet(0);
   /** @pdRoleInfo migr=no name=Topic assc=parentAndChildren coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   private Set topicB = new HashSet(0);
   /** @pdRoleInfo migr=no name=Subject assc=topicOfSubject coll=java.util.Collection impl=java.util.HashSet mult=0..* side=A */
   private Set SubjectTopicMapping = new HashSet(0);
   /** @pdRoleInfo migr=no name=Topic assc=parentAndChildren mult=0..1 side=A */
   public Topic TOPIC_PARENT_ID;
   
   public static List <Topic> getAllTopic(Session session)
   {
	   Query query = session.createQuery("from Topic");                
	   List <Topic> listOfTopic = query.list();
	   return listOfTopic;
   }
   
   public static Set getTopicBySubject(String subjectID, Session session)
   {
	   Subject s = Subject.getSubjectById(subjectID, session);
	   return s.getSubjectTopicMapping();
   }
   
   public static Topic  getTopicByID(Integer topicID, Session session)
   {
	   return (Topic) session.load(Topic.class, topicID);
   }
   
   public static List <Topic> getTopicByTopTopic(Integer topTopicID, Session session)
   {
	   Query query = session.createQuery("from Topic where TOP_TOPIC_ID = '" + topTopicID + "'");                
	   List <Topic> listOfTopic = query.list();
	   return listOfTopic;
   }
   
   
   /** @pdOid cd1fb017-b5e3-4c08-84cd-f93e2c40d8f1 */
   public Integer getTopicId() {
      return topicId;
   }
   
   /** @param newTopicId
    * @pdOid be10e163-1e57-483f-b4d9-ce97c7c73f41 */
   public void setTopicId(Integer newTopicId) {
      topicId = newTopicId;
   }
   
   /** @pdOid 32bc1622-76c9-439d-bc8f-c38a2f7d4e05 */
   public Topic() {
      // TODO: implement
   }
   
   /** @pdOid 95585c03-bb4e-424d-a3f8-51c8b6ebbcfc */
   public java.lang.String getTopicName() {
      return topicName;
   }
   
   /** @param newTopicName
    * @pdOid de9f9252-3281-4dac-8681-6eca2c1d05dc */
   public void setTopicName(java.lang.String newTopicName) {
      topicName = newTopicName;
   }
   
   /** @pdOid d58a102a-0636-49ba-8681-9ed083377318 */
   public java.lang.String getTopicNote() {
      return topicNote;
   }
   
   /** @param newTopicNote
    * @pdOid 4e048812-8001-4a3a-a7da-4355adb4c065 */
   public void setTopicNote(java.lang.String newTopicNote) {
      topicNote = newTopicNote;
   }
   
   
   public Set getTopicQuestionMapping() {
		return this.TopicQuestionMapping;
	}

	public void setTopicQuestionMapping(Set TopicQuestionMapping) {
		this.TopicQuestionMapping = TopicQuestionMapping;
	}
	
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTopicQuestionMapping() {
      if (TopicQuestionMapping == null)
         TopicQuestionMapping = new java.util.HashSet<Question>();
      return TopicQuestionMapping.iterator();
   }
   
   
   /** @pdGenerated default add
     * @param newQuestion */
   public void addTopicQuestionMapping(Question newQuestion) {
      if (newQuestion == null)
         return;
      if (this.TopicQuestionMapping == null)
         this.TopicQuestionMapping = new java.util.HashSet<Question>();
      if (!this.TopicQuestionMapping.contains(newQuestion))
      {
         this.TopicQuestionMapping.add(newQuestion);
         newQuestion.addTopicQuestionMapping(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestion */
   public void removeTopicQuestionMapping(Question oldQuestion) {
      if (oldQuestion == null)
         return;
      if (this.TopicQuestionMapping != null)
         if (this.TopicQuestionMapping.contains(oldQuestion))
         {
            this.TopicQuestionMapping.remove(oldQuestion);
            oldQuestion.removeTopicQuestionMapping(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTopicQuestionMapping() {
      if (TopicQuestionMapping != null)
      {
         Question oldQuestion;
         for (java.util.Iterator iter = getIteratorTopicQuestionMapping(); iter.hasNext();)
         {
            oldQuestion = (Question)iter.next();
            iter.remove();
            oldQuestion.removeTopicQuestionMapping(this);
         }
      }
   }
   public Set getTopicB() {
		return this.topicB;
	}

	public void setTopicB(Set topicB) {
		this.topicB = topicB;
	}
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTopicB() {
      if (topicB == null)
         topicB = new java.util.HashSet<Topic>();
      return topicB.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newTopicB */
//   public void setTopicB(java.util.Collection<Topic> newTopicB) {
//      removeAllTopicB();
//      for (java.util.Iterator iter = newTopicB.iterator(); iter.hasNext();)
//         addTopicB((Topic)iter.next());
//   }
//   
   /** @pdGenerated default add
     * @param newTopic */
   public void addTopicB(Topic newTopic) {
      if (newTopic == null)
         return;
      if (this.topicB == null)
         this.topicB = new java.util.HashSet<Topic>();
      if (!this.topicB.contains(newTopic))
      {
         this.topicB.add(newTopic);
         newTopic.setTOPIC_PARENT_ID(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTopic */
   public void removeTopicB(Topic oldTopic) {
      if (oldTopic == null)
         return;
      if (this.topicB != null)
         if (this.topicB.contains(oldTopic))
         {
            this.topicB.remove(oldTopic);
            oldTopic.setTOPIC_PARENT_ID((Topic)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTopicB() {
      if (topicB != null)
      {
         Topic oldTopic;
         for (java.util.Iterator iter = getIteratorTopicB(); iter.hasNext();)
         {
            oldTopic = (Topic)iter.next();
            iter.remove();
            oldTopic.setTOPIC_PARENT_ID((Topic)null);
         }
      }
   }
   
	public Set getSubjectTopicMapping() {
		return this.SubjectTopicMapping;
	}

	public void setSubjectTopicMapping(Set SubjectTopicMapping) {
		this.SubjectTopicMapping = SubjectTopicMapping;
	}
	
//   /** @pdGenerated default getter */
//   public java.util.Collection<Subject> getSubjectTopicMapping() {
//      if (SubjectTopicMapping == null)
//         SubjectTopicMapping = new java.util.HashSet<Subject>();
//      return SubjectTopicMapping;
//   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorSubjectTopicMapping() {
      if (SubjectTopicMapping == null)
         SubjectTopicMapping = new java.util.HashSet<Subject>();
      return SubjectTopicMapping.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newSubjectTopicMapping */
//   public void setSubjectTopicMapping(java.util.Collection<Subject> newSubjectTopicMapping) {
//      removeAllSubjectTopicMapping();
//      for (java.util.Iterator iter = newSubjectTopicMapping.iterator(); iter.hasNext();)
//         addSubjectTopicMapping((Subject)iter.next());
//   }
//   
   /** @pdGenerated default add
     * @param newSubject */
   public void addSubjectTopicMapping(Subject newSubject) {
      if (newSubject == null)
         return;
      if (this.SubjectTopicMapping == null)
         this.SubjectTopicMapping = new java.util.HashSet<Subject>();
      if (!this.SubjectTopicMapping.contains(newSubject))
      {
         this.SubjectTopicMapping.add(newSubject);
         newSubject.addSubjectTopicMapping(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldSubject */
   public void removeSubjectTopicMapping(Subject oldSubject) {
      if (oldSubject == null)
         return;
      if (this.SubjectTopicMapping != null)
         if (this.SubjectTopicMapping.contains(oldSubject))
         {
            this.SubjectTopicMapping.remove(oldSubject);
            oldSubject.removeSubjectTopicMapping(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllSubjectTopicMapping() {
      if (SubjectTopicMapping != null)
      {
         Subject oldSubject;
         for (java.util.Iterator iter = getIteratorSubjectTopicMapping(); iter.hasNext();)
         {
            oldSubject = (Subject)iter.next();
            iter.remove();
            oldSubject.removeSubjectTopicMapping(this);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Topic getTOPIC_PARENT_ID() {
      return TOPIC_PARENT_ID;
   }
   
   /** @pdGenerated default parent setter
     * @param newTopic */
   public void setTOPIC_PARENT_ID(Topic newTopic) {
      if (this.TOPIC_PARENT_ID == null || !this.TOPIC_PARENT_ID.equals(newTopic))
      {
         if (this.TOPIC_PARENT_ID != null)
         {
            Topic oldTopic = this.TOPIC_PARENT_ID;
            this.TOPIC_PARENT_ID = null;
            oldTopic.removeTopicB(this);
         }
         if (newTopic != null)
         {
            this.TOPIC_PARENT_ID = newTopic;
            this.TOPIC_PARENT_ID.addTopicB(this);
         }
      }
   }

}